using System.Data;
using System.Data.SqlClient;
using VanTaiProperty;
namespace VanTaiData
{
    public class clsTMVehicleController
    {
        private clsConnect cls = new clsConnect();
        private DataTable dt;
        #region[Get-Data]
        public DataTable BindGirdTMVehicle()
        {
            return cls.BindGridData("sp_TMVehicle");
        }
        public DataTable BindGirdTMVehicle_Detail_Edit(int id)
        {
            return cls.LayDuLieuParameter("sp_TMVehicle_Detail_Edit","@Id", id);
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertTMVehicle(clsTMVehicleProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Vehicle_Number", data.Vehicle_Number);
            cls.AddParameter("@Vehicle_Type_Vehicle_ID", data.Vehicle_Type_Vehicle_ID);
            cls.AddParameter("@Member_ID", data.Member_ID);
            cls.AddParameter("@Division_Old_ID", data.Division_Old_ID);
            cls.AddParameter("@Division_New_ID", data.Division_New_ID);
            cls.AddParameter("@VehicleGroup_Old_ID", data.VehicleGroup_Old_ID);
            cls.AddParameter("@VehicleGroup_New_ID", data.VehicleGroup_New_ID);
            cls.AddParameter("@Decision_ID", data.Decision_ID);
            cls.AddParameter("@Create_Date_Vehicle", data.Create_Date_Vehicle);
            cls.AddParameter("@Active_Vehicle", data.Active_Vehicle);
            cls.AddParameter("@Note_Vehicle", data.Note_Vehicle);
            cls.AddParameter("@HMCT_ID", data.HMCT_ID);
            cls.AddParameter("@MaCha", data.MaCha);
            cls.AddParameter("@Date_Of_Reg", data.Date_Of_Reg);
            cls.AddParameter("@Date_Of_Expires", data.Date_Of_Expires);
            cls.ExecuteNonQuery("sp_TMVehicle_Insert");
            return true;
        }
        public bool UpdateTMVehicle(clsTMVehicleProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Vehicle_ID", data.Vehicle_ID);
            cls.AddParameter("@Vehicle_Number", data.Vehicle_Number);
            cls.AddParameter("@Vehicle_Type_Vehicle_ID", data.Vehicle_Type_Vehicle_ID);
            cls.AddParameter("@Member_ID", data.Member_ID);
            cls.AddParameter("@Division_Old_ID", data.Division_Old_ID);
            cls.AddParameter("@Division_New_ID", data.Division_New_ID);
            cls.AddParameter("@VehicleGroup_Old_ID", data.VehicleGroup_Old_ID);
            cls.AddParameter("@VehicleGroup_New_ID", data.VehicleGroup_New_ID);
            cls.AddParameter("@Decision_ID", data.Decision_ID);
            cls.AddParameter("@Create_Date_Vehicle", data.Create_Date_Vehicle);
            cls.AddParameter("@Active_Vehicle", data.Active_Vehicle);
            cls.AddParameter("@Note_Vehicle", data.Note_Vehicle);
            cls.AddParameter("@HMCT_ID", data.HMCT_ID);
            cls.AddParameter("@MaCha", data.MaCha);
            cls.AddParameter("@Date_Of_Reg", data.Date_Of_Reg);
            cls.AddParameter("@Date_Of_Expires", data.Date_Of_Expires);
            cls.ExecuteNonQuery("sp_TMVehicle_Update");
            return true;
        }
        public bool DeleteTMVehicle(int id)
        {
            cls.Delete("sp_TMVehicle_Delete", "@Vehicle_ID", id);
            return true;
        }
        public bool TMVehicle_Check_Delete_TMCommandTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMVehicle_Check_Delete_TMCommandTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMVehicle_Check_Delete_TMPlan_TransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMVehicle_Check_Delete_TMPlan_TransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMVehicle_Check_Delete_TMSalesReport(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMVehicle_Check_Delete_TMSalesReport", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMVehicle_Check_Delete_TMDiaryTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMVehicle_Check_Delete_TMDiaryTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMVehicle_Check_Contract(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMVehicle_Check_Contract", "@ID", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion

        #region[Search]
        public DataTable Search(string keywords)
        {
            return cls.Search("sp_TMVehicle_Search", "@KEYWORDS", keywords);
        }
        #endregion
    }
}